#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
资金 - 资金重新冻结功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.fund_deferred_service import FundService
from jlpay.model.fund_deferred import FundRefreezeRequest


class FundRefreezeExample(BaseExample):
    """资金重新冻结示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.fund.deferred.refreeze")
        # 创建FundService实例
        self.fund_service = FundService(self.config)
    
    def build_fund_refreeze_request(self):
        """构建资金重新冻结请求"""
        request = FundRefreezeRequest()
        
        # 设置请求参数
        request.set_merch_no("849551860110001")
        request.set_out_order_id("test_refreeze_202412200001")
        request.set_ori_out_order_id("test_freeze_202412200001")  # 原冻结订单ID
        request.set_reason("重新冻结测试")
        request.set_remark("重新冻结测试")
        
        return request
    
    def demo(self):
        """执行资金重新冻结示例"""
        self.logger.info("开始执行资金重新冻结示例")
        
        # 创建资金重新冻结请求
        request = self.build_fund_refreeze_request()
        
        # 发送请求并处理响应
        response = self.send_request_and_handle_response(
            self.fund_service.refreeze_fund,
            "资金重新冻结",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")
        
        self.logger.info("资金重新冻结示例执行完毕")


if __name__ == "__main__":
    logger = FundRefreezeExample().logger
    logger.info("==================================================")
    logger.info("===== 资金重新冻结示例 开始 =====")
    logger.info("==================================================")
    
    example = FundRefreezeExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 资金重新冻结示例执行完毕 =====")
    logger.info("==================================================") 